package threadLocal;

public class ThreadLocalDemo {

    public ThreadLocal<Integer> threadLocal = new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };
    public void get() {
        for (int i = 0; i < 3; i++) {
            threadLocal.set(threadLocal.get() + 1);
            System.out.println(Thread.currentThread().getName() + "--" + threadLocal.get());
        }

    }

    public static void main(String[] args) {
        ThreadLocalDemo localMapDemo = new ThreadLocalDemo();
        for (int i = 0; i < 3; i++) {
            new Thread(() -> localMapDemo.get()).start();
        }
    }

}
